package tcpGroupChat;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ClientReadThread extends Thread {

    private Socket socket;

    public ClientReadThread(){

    }

    public ClientReadThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            //通过Scoket获取一个输入流
            InputStream inputStream = socket.getInputStream();
            //将其包装成一个高级数据流
            DataInputStream dataInputStream = new DataInputStream(inputStream);
            while (true) {
                //获取发送的数据
                try {
                    String s = dataInputStream.readUTF();
                    System.out.println(s);
                } catch (Exception e) {
                    System.out.println("自己下线了！！！");
                    dataInputStream.close();
                    socket.close();
                    break;
                }
            }
        } catch (Exception ignored) {

        }
    }
}
